﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using RBS.Common;

namespace RBS.Web.Hotel.Models.Dine
{
    /// <summary>
    /// 订单信息ViewModel
    /// </summary>
    public class OrderViewModel
    {
        public OrderViewModel() {
            OrderDetails = new List<OrderDetailViewModel>();
        }

        #region 基本信息

        /// <summary>
        /// 订单id
        /// </summary>
        public Int32 OrderID { get; set; }
        /// <summary>
        /// 订单状态
        /// </summary>
        public OrderState OrderState { get; set; }
        /// <summary>
        /// 预订渠道
        /// </summary>
        public OrderChannel OrderChannel { get; set; }
        /// <summary>
        /// 联系人
        /// </summary>		 
        public string ContactUser { get; set; }
        /// <summary>
        /// 用户手机
        /// </summary>		 
        public string ContactMobile { get; set; }
        /// <summary>
        /// 订单备注
        /// </summary>		 
        public string OrderRemark { get; set; }
        /// <summary>
        /// 订单总金额
        /// </summary>		 
        public decimal OrderAmount { get; set; }
        /// <summary>
        /// 已收金额
        /// </summary>		 
        public decimal RecAmount { get; set; }
        /// <summary>
        /// decimal(18, 2)
        /// </summary>		 
        public decimal DisAmount { get; set; }
        /// <summary>
        /// decimal(18, 2)
        /// </summary>		 
        public decimal AccAmount { get; set; }
        /// <summary>
        /// 支付方式
        /// </summary>		 
        public PayType PayType { get; set; }
        /// <summary>
        /// 支付时间
        /// </summary>		 
        public DateTime PayTime { get; set; }
        /// <summary>
        /// 预订吃饭日期
        /// </summary>		 
        public string ReserveDate { get; set; }
        /// <summary>
        /// 预订吃饭时间
        /// </summary>		 
        public string ReserveTime { get; set; }
        /// <summary>
        /// 吃饭人数
        /// </summary>		 
        public int DineNum { get; set; }
        /// <summary>
        /// 预定人
        /// </summary>		 
        public int U_Id { get; set; }
        /// <summary>
        /// CreateTime
        /// </summary>		 
        public DateTime CreateTime { get; set; }
        /// <summary>
        /// CreateUser
        /// </summary>		 
        public string CreateUser { get; set; }
        /// <summary>
        /// LastModifyDate
        /// </summary>		 
        public DateTime LastModifyDate { get; set; }
        /// <summary>
        /// LastModifyUser
        /// </summary>		 
        public string LastModifyUser { get; set; }
        public DateTime OrderTime { get; set; }  
        #endregion

        #region 酒店|餐桌信息

        /// <summary>
        /// 酒店id
        /// </summary>
        public Int32 HotelId { get; set; }

        /// <summary>
        /// 酒店
        /// </summary>
        public String HotelName { get; set; }

        /// <summary>
        /// 餐桌
        /// </summary>
        public String DineTable { get; set; }

        /// <summary>
        /// 座位情况（大厅，包间）
        /// </summary>		 
        public string Dinecondition { get; set; }  

        #endregion

        /// <summary>
        /// 订单详细
        /// </summary>
        public IList<OrderDetailViewModel> OrderDetails { get; set; }

        #region Public properties

        /// <summary>
        /// 能否取消
        /// </summary>
        public Boolean IsCanCancel {
            get {
                //if (this.OrderState != OrderState.订单取消 && this.OrderState != OrderState.待评论 && this.OrderState != OrderState.已完成 && this.OrderState != OrderState.已评论)
                if (this.OrderState == OrderState.下单 || this.OrderState == OrderState.点餐 || this.OrderState == OrderState.预定成功)  
                return true;
                else return false;
            }
        }

        /// <summary>
        /// 能否确认订单
        /// </summary>
        public Boolean IsCanConfirm {
            get {
                if (this.OrderState == OrderState.下单)
                    return true;
                else return false;
            }
        }

        /// <summary>
        /// 能否结帐
        /// </summary>
        public Boolean IsCanCheckout {
            get {
                if (this.OrderState == OrderState.就餐)
                    return true;
                else return false;
            }
        }

        /// <summary>
        /// 就坐
        /// </summary>
        public Boolean IsCanCheckIn
        {
            get
            {
                if (this.OrderState == OrderState.预定成功)
                    return true;
                else return false;
            }
        }
        #endregion

    }

    /// <summary>
    /// 订单详细ViewModel
    /// </summary>
    public class OrderDetailViewModel {

        /// <summary>
        /// Id
        /// </summary>		 
        public int Id { get; set; }   
        /// <summary>
        /// 订单Id
        /// </summary>		 
        public int OrderId { get; set; }
        /// <summary>
        /// 菜名Id
        /// </summary>		 
        public int HCId { get; set; }
        /// <summary>
        /// 菜名
        /// </summary>		 
        public string CName { get; set; }
        /// <summary>
        /// Num
        /// </summary>		 
        public int Num { get; set; }
        /// <summary>
        /// Price
        /// </summary>		 
        public decimal Price { get; set; }
        /// <summary>
        /// 优惠价格
        /// </summary>		 
        public decimal DisAmount { get; set; }
        /// <summary>
        /// 是否客人点菜
        /// </summary>		 
        public int IsGuest { get; set; }
        /// <summary>
        /// UId
        /// </summary>		 
        public int UId { get; set; }
        /// <summary>
        /// 状态：0=已确认，1=已下锅，2=已上桌，9=取消
        /// </summary>		 
        public int State { get; set; }
        public DateTime  OperateDate { get; set; }      
  
    }

    /// <summary>
    /// 订单操作记录ViewModel
    /// </summary>
    public class OperateRecordViewModel {
        public Int32 Id { get; set; }
        public Int32 OrderId { get; set; }
        public Int32 OrderProductId { get; set; }
        public Int32 OperateType { get; set; }
        public String OperateDesc { get; set; }
        public Int32 OperateUserId { get; set; }
        public String OperateUser { get; set; }
        public DateTime OperateDate { get; set; }
    }

    /// <summary>
    /// 订单查询条件
    /// </summary>
    public class OrderQueryCondition{

        public OrderQueryCondition() {
            this.HotelId = 0;
            this.OrderId = String.Empty;
            this.ContactUser = String.Empty;
            this.ContactMobile = String.Empty;
            this.BeginDate = String.Empty;
            this.EndDate = String.Empty;
            this.OrderState = String.Empty;
            this.OrderChannel = String.Empty;
            this.PageIndex = 1;
            this.PageSize = 10;
            this.OrderField = String.Empty;
        }

        public Int32 HotelId { get; set; }
        public String OrderId { get; set; }
        public String ContactUser { get; set; }
        public String ContactMobile { get; set; }
        public String BeginDate { get; set; }
        public String EndDate { get; set; }
        public String OrderState { get; set; }
        public String OrderChannel { get; set; }

        public Int32 PageIndex { get; set; }
        public Int32 PageSize { get; set; }
        public String OrderField { get; set; }

        public String ConvertToSql() {
            StringBuilder sqlBuilder = new StringBuilder(); 
            if (this == null) return String.Empty;
            if (this.HotelId > 0) sqlBuilder.AppendFormat(" and H_Id = '{0}' ", this.HotelId);
            if (!String.IsNullOrEmpty(this.OrderId)) sqlBuilder.AppendFormat(" and Id = '{0}' ", this.OrderId);
            if (!String.IsNullOrEmpty(this.ContactUser)) sqlBuilder.AppendFormat(" and ContactUser = '{0}' ", this.ContactUser);
            if (!String.IsNullOrEmpty(this.ContactMobile)) sqlBuilder.AppendFormat(" and ContactMobile = '{0}' ", this.ContactMobile);
            if (!String.IsNullOrEmpty(this.BeginDate)) sqlBuilder.AppendFormat(" and OrderTime >= '{0}' ", this.BeginDate);
            if (!String.IsNullOrEmpty(this.EndDate)) sqlBuilder.AppendFormat(" and OrderTime <= '{0}' ", this.EndDate);
            if (!String.IsNullOrEmpty(this.OrderState)) 
            {
                if (this.OrderState == "7" || this.OrderState == "6" || this.OrderState == "5")
                {
                    sqlBuilder.Append(" and OrderState in (5,6,7) ");
                }
                else
                {
                    sqlBuilder.AppendFormat(" and OrderState = '{0}' ", this.OrderState);  
                }
            
            }
            if (!String.IsNullOrEmpty(this.OrderChannel)) sqlBuilder.AppendFormat(" and OrderChannel = '{0} '", this.OrderChannel);

            return sqlBuilder.ToString();
        }

    }

    /// <summary>
    /// 订单状态
    /// </summary>
    public enum OrderState
    {
       /* 已取消 = -1,
        下单未确认 = 0,
        已确认 = 1,
        就餐中 = 2,
        已完成 = 3
*/ 
           下单 = -1,  
           点餐=1,  
           预定成功,  
           订单取消,  
           就餐,  
           待评论,  
           已评论,
           已完成

    }

    /// <summary>
    /// 订单渠道
    /// </summary>
    public enum OrderChannel
    {
        网站 = 0,
        手机预订 = 1,
        电话 = 2,
        门店 = 3
    }

    /// <summary>
    /// 支付方式
    /// </summary>
    public enum PayType
    {
        现金 = 0,
        刷卡 = 1
    }

}